package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.WorkTypeObject;
import com.tbit.uqbike.service.business.ManualWorkOrderService;
import com.tbit.uqbike.webmanager.dao.core.ManualWorkOrderDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：hzw
 * @date ：Created in 2021/9/2 19:34
 * @description：手动工单类型设置业务层
 * @modified By：
 * @version: $
 */
@Slf4j
@Service(value = "manualWorkOrderService")
public class ManualWorkOrderServiceImpl implements ManualWorkOrderService {
    @Autowired
    private ManualWorkOrderDao manualWorkOrderDao;

    @Override
    public List<WorkTypeObject> queryPage(Integer accountId, Integer pageNO, Integer rowCount) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("pageNO", (pageNO - 1) * rowCount);
        map.put("rowCount", rowCount);
        return manualWorkOrderDao.queryPage(map);
    }

    @Override
    public Integer queryCount(Integer accountId) {
        return manualWorkOrderDao.queryCount(accountId);
    }

    @Override
    public Integer insertType(WorkTypeObject workType) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", workType.getAccountId());
        map.put("workType", workType.getWorkType());
        map.put("workName", workType.getWorkName());
        map.put("addTime", new Date());

        List<WorkTypeObject> Explain = manualWorkOrderDao.getExplain(map);
        if (!Explain.isEmpty()) {
            throw new BaseException(SystemCodeEnum.ACCOUNT_NAME_EXIT);
        } else {
            return manualWorkOrderDao.insertType(map);
        }
    }

    @Override
    public Integer updateWorkType(WorkTypeObject workType) {
        Map<String, Object> map = new HashMap<>();
        map.put("accountId", workType.getAccountId());
        map.put("workType", workType.getWorkType());
        map.put("workName", workType.getWorkName());
        List<WorkTypeObject> Explain = manualWorkOrderDao.getExplain(map);
        if (!Explain.isEmpty()) {
            throw new BaseException(SystemCodeEnum.ACCOUNT_NAME_EXIT);
        } else {
            return manualWorkOrderDao.updateType(map);
        }
    }

    @Override
    public void delWorkType(WorkTypeObject workType) {
        manualWorkOrderDao.delType(workType);
    }
}
